package service

import (
	"errors"
	"organoid_public/domain/fitness/enum"
	"organoid_public/domain/fitness/model"
	"organoid_public/domain/fitness/respository"
)

type OpenAppServiceD struct {
	repo respository.OpenAppRepoInterface
}

func NewOpenAppServiceD(repo respository.OpenAppRepoInterface) OpenAppServiceInterface {
	return &OpenAppServiceD{repo: repo}
}

func (o *OpenAppServiceD) DiscernRepBelongApp(appid string) (*model.OpenApp, error) {
	openApp, err := o.repo.GetAppInfo(appid)
	if err != nil {
		return nil, err
	}
	if openApp.Id <= 0 {
		return nil, errors.New("非法应用")
	}
	if openApp.Status != enum.StatusNormal {
		return nil, errors.New("应用状态不可用")
	}
	return openApp, nil
}
